package com.hnrd.crud.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import com.hnrd.crud.mapper.PermissionMapper;
import com.hnrd.crud.pojo.Permission;
import com.hnrd.crud.service.PermissionService;
@Service
public class PermissionServiceImpl implements PermissionService{
	private Map<String, Object> map;
	@Autowired
	private PermissionMapper permissionMapper;
	@Override
	public ResponseEntity<Map<String, Object>> insert(Permission permission) {//添加新权限
		try {
			int result =  permissionMapper.insert(permission);
			map.put("result", result);
			map.put("msg","添加成功！");
			return new ResponseEntity<>(map,HttpStatus.OK);
		} catch (Exception e) {
			map.put("msg","添加失败！");
			return new ResponseEntity<>(map,HttpStatus.BAD_REQUEST);
		}
			
	}
	@Override
	public ResponseEntity<Map<String, Object>> delete(Integer permissionId) {
		try {
			int result=permissionMapper.deleteByPrimaryKey(permissionId);
			map.put("result", result);
			map.put("msg","删除成功！");
			return new ResponseEntity<>(map,HttpStatus.OK);
		} catch (Exception e) {
			map.put("msg","删除失败！");
			return new ResponseEntity<>(map,HttpStatus.BAD_REQUEST);
		}
	}
	@Override
	public ResponseEntity<Map<String, Object>> update(Permission permission) {
		try {
			int result=permissionMapper.updateByPrimaryKey(permission);
			map.put("result", result);
			map.put("msg","更新成功！");
			return new ResponseEntity<>(map,HttpStatus.OK);
		} catch (Exception e) {
			map.put("msg","更新失败！");
			return new ResponseEntity<>(map,HttpStatus.BAD_REQUEST);
		}
	}
	@Override
	public ResponseEntity<Map<String, Object>> selectPermissions() {
		try {
			List<Permission> result=permissionMapper.selectAll();
			map.put("msg","获取权限列表成功！");
			map.put("result", result);
			return new ResponseEntity<>(map,HttpStatus.OK);
		} catch (Exception e) {
			map.put("msg","获取权限列表失败！");
			return new ResponseEntity<>(map,HttpStatus.BAD_REQUEST);
		}
	}
	
}
